package com.ld.security.common.core.context;

import java.util.HashMap;
import java.util.Map;

/**
 * 线程工具
 * 用来鉴权解耦
 */
public class BaseContext {

    public static ThreadLocal<Map<Object, Object>> threadLocal = new ThreadLocal<Map<Object, Object>>();


    public static void set(Object key, Object value) {
        Map<Object, Object> map = threadLocal.get();
        if (map == null) {
            map = new HashMap<Object, Object>();
            threadLocal.set(map);
        }
        map.put(key, value);
    }

    public static <E> E get(Object key){
        Map<Object, Object> map = threadLocal.get();
        if (map == null) {
            map = new HashMap<Object, Object>();
            threadLocal.set(map);
        }
        return (E)map.get(key);
    }


    public static void remove(){
        threadLocal.remove();
    }

}
